/**
 * Copyright 2012 Roger Cockshutt
 * krakenbrau@gmail.com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.googlecode.parallelrl.display;

import com.googlecode.parallelrl.Config;
import com.googlecode.parallelrl.data.LevelProvider;
import com.googlecode.parallelrl.util.ColoredChar;
import com.googlecode.parallelrl.util.Point2D;

/**
 * @author Roger Cockshutt
 *
 */
public class Mapper {
	
	private static Mapper instance = null;
	
	private Mapper() {
		size = Config.mapWindowSize;
		position = Config.mapWindowPosition;
	}
	
	public static Mapper get() {
		if (instance == null) {
			instance = new Mapper();
		}
		return instance;
	}
	
	private final Point2D size;
	private final Point2D position;
	
	public void update() {
		ColoredChar[][] displayRegion = 
				LevelProvider.getCurrentLevel().getDisplayRegion(size);
		if (displayRegion == null) {
			return;			// The player is probably dead.
		}
		for (int iy = 0; iy < displayRegion.length; iy++) {
			for (int ix = 0; ix < displayRegion[0].length; ix++) {
				Screen.get().putch(displayRegion[iy][ix].getChar(), iy + position.y, ix + position.x, displayRegion[iy][ix].getColor(), Colors.libTCOD.black.normal);
			}
		}
	}

}
